package cn.com.support.context;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 请求时数据
 * 
 * @since 2012-3-9 下午9:33:58
 * @version 1.0
 * @author Microbun
 */
public abstract class RunData {

	private HttpServletRequest request;

	private HttpServletResponse response;

	private static ThreadLocal<RunData> rundataLocal=new ThreadLocal<RunData>();

	/**
	 * 子类必须构造函数必须调用这个构造函数
	 * 
	 * @param request
	 * @param response
	 */
	protected RunData(HttpServletRequest request, HttpServletResponse response) {
		this.request = request;
		this.response = response;
	}

	/**
	 * 设置Rundata，给子类调用，传输实例化Rundata
	 * 
	 * @param rundata
	 */
	protected static void setRundata(RunData rundata) {
		rundataLocal.set(rundata);
	}

	/**
	 * 获取当前RunData
	 * 
	 * @return RunData
	 */
	public static RunData get() {
		return rundataLocal.get();
	}

	/**
	 * 获取 HttpServletRequest
	 * 
	 * @return HttpServletRequest
	 */
	public HttpServletRequest getHttpServletRequest() {
		return request;
	}

	/**
	 * 获取HttpServletResponse
	 * 
	 * @return HttpServletResponse
	 */
	public HttpServletResponse getHttpServletResponse() {
		return response;
	}

	/**
	 * 获取 HttpSession
	 * 
	 * @return HttpSession
	 */
	public HttpSession getHttpSession() {
		return request.getSession();
	}

}
